<?php

class Jhub1_View_Helper_Translatex extends Zend_View_Helper_Abstract {

    protected $_keyword;
    protected $_country;
    protected $_language;

    /*
     * This helper makes language translations 
     *
     *
     */


    public function translatex($name) {
        $session = new Zend_Session_Namespace('GrandMarnier');
        $this->_language = $session->userLanguage;
        $this->_country = $session->country;
        if($this->_country == "FR" && $name == 'SH_SUNSET_HOUR') {
            $this->_keyword = 'SH_SUNSET_HOUR_TAKER';
        } else {
            $this->_keyword = $name;
        }
        return $this->transl();
    }

    public function transl() {
        $logger = Zend_Registry::get('log');
        $translation = new Application_Model_DbTable_Translation();
        $translation->setLanguage($this->_language);
        $transl = $translation->getAllTranslations();
#        Zend_Debug::dump($transl, '$transl', true);
        if (array_key_exists($this->_keyword, $transl)) {
            if ($transl[$this->_keyword] != "") {
                $logger->info($this->_keyword . ' : ' . $transl[$this->_keyword]);
                return $transl[$this->_keyword];
            } else {
                $logger->err($this->_keyword .  ' :  --no translation--');
                return $this->_keyword;
            }
        } else {
            $logger->err($this->_keyword . ' :  --no translation--');
            return $this->_keyword;
        }
    }

    // The default representation of the greeting. Let's be nice, by default.
    public function __toString() {
        return "";
    }

}

#echo  $this->translatex('PRODUCT_HISTORY_WQ');
?>